package com.zl.data.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import com.zl.data.config.DataConstant;
import com.zl.data.db.DataUtil;

/**
 * @author ZL @朱林</a>
 * @Version 1.0
 * @Description TODO
 * @date 2021/01/11  14:41
 */
public class DataMangerService extends Service {
    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(DataConstant.TAG, "DataMangerService;onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(DataConstant.TAG, "DataMangerService;onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        DataUtil.getInstance(getContext()).onDestroy();
        super.onDestroy();
    }

    public static Context getContext() {
        return mContext;
    }

    public static void setContext(Context mContext) {
        DataMangerService.mContext = mContext;
    }

    public synchronized static boolean encode(String key, byte[] value) {
        return DataUtil.getInstance(getContext()).replace(key, value);
    }

    public synchronized static byte[] decodeBytes(String key) {
        return DataUtil.getInstance(getContext()).query(key);
    }

    public synchronized static boolean removeKey(String key) {
        return DataUtil.getInstance(getContext()).delete(key);
    }


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
